Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@enonic-types/global
Advanced tools
TypeScript definitions for global variables of Enonic XP
npm i --save-dev @enonic-types/global
Add the corresponding types to your tsconfig.json
file that is used for application's server-side TypeScript code:
{
"compilerOptions": {
"types": [
"@enonic-types/global"
]
}
}
After that, all the global XP variables will be typed.
Import functions, such as require
, will return typed objects if the corresponding types for imported libraries are also added to
your tsconfig.json
.
To add support for type resolution for the custom libraries via require
, you can redeclare the XpLibraries
interface in global scope,
which will lead to declaration merging:
declare global {
interface XpLibraries {
'/lib/custom/mylib': typeof import('./mylib');
}
}
If you want to use custom import functions, like __non_webpack_require__
with Webpack, just use global XpRequire
type for this:
declare const __non_webpack_require__: XpRequire;
To create a new bean, a __.newBean()
function must be used. Making it return a proper type can be done in two ways. Say you have created
an interface for that been somewhere in your project:
interface SomeHelper {
help(text: string): void;
}
You can pass the type argument explicitly. This option is a bit cleaner.
const helper = __.newBean<SomeHelper>('com.me.project.SomeHelper');
Or you can map the bean name to bean interface. It may be a preferable way to do it, if the bean is used across multiple files:
declare global {
interface XpBeans {
'com.me.project.SomeHelper': SomeHelper;
}
}
const helper = __.newBean('com.me.project.SomeHelper');
FAQs
Global variables and functions type definition.
We found that @enonic-types/global demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.